package model_response

import "go-admin/internal/model"

type ListDeptResponse struct {
	CommonId
	DeptName string `json:"deptName"` // 部门名称
	ParentId string `json:"parentId"` // 父级部门id
	Sort     int64  `json:"sort"`     // 排序
	IsBanned string `json:"isBanned"` // 是否禁用
	CommonCreatedOn
	Children []*ListDeptResponse `json:"children"` // 子级
}

type DeptDetail struct {
	CommonId
	DeptName string `json:"deptName"` // 部门名称
	ParentId string `json:"parentId"` // 父级部门id
	Sort     int64  `json:"sort"`     // 排序
	IsBanned string `json:"isBanned"` // 是否禁用
	Remark   string `json:"remark"`   // 备注
}

func ModelToDetailDeptRes(model *model.Dept) *DeptDetail {
	dept := &DeptDetail{
		CommonId: CommonId{Id: model.Id},
		DeptName: model.DeptName,
		ParentId: model.ParentId,
		Sort:     model.Sort,
		IsBanned: model.IsBanned,
		Remark:   model.Remark,
	}
	return dept
}

// 模型转详情结构体
func ModelToListDeptTreeRes(models []*model.Dept) []*ListDeptResponse {

	list := make([]*ListDeptResponse, 0)
	for _, m := range models {
		l := ListDeptResponse{
			CommonId:        CommonId{Id: m.Id},
			DeptName:        m.DeptName,
			ParentId:        m.ParentId,
			Sort:            m.Sort,
			IsBanned:        m.IsBanned,
			CommonCreatedOn: CommonCreatedOn{CreatedOn: m.CreatedOn},
		}
		childList := make([]*ListDeptResponse, 0)
		l.Children = childList
		list = append(list, &l)
	}
	return list
}
